<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>销售统计</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
	<style>
	.orderdetail{background:#f7f7f8;width: 94%;box-sizing:border-box;margin:0 10px;display:flex;flex-direction:column;}
	.orderdetail *{box-sizing:border-box;}
	.address{ display:flex;align-items:center;width: 100%; padding:5px; background: #FFF;}
	.address .img{width:30px}
	.address img{width:25px; height:25px;}
	.address .info{flex:1;display:flex;flex-direction:column;}
	.address .info .t1{ font-weight:bold}

	.express { width:100%;background: #fff; padding:5px;display:flex;align-items:center;margin-top:5px;}
	.express .f1{ width:30px;font-size:20px;color:#999}
	.express .f2{display:flex;flex-direction:column;flex:auto}

	.product{width:100%; padding:5px;background: #FFF;margin-top:5px;}
	.product .content{display:flex;position:relative;width: 100%; padding:5px 0px;border-bottom: 1px #e5e5e5 dashed;position:relative}
	.product .content:last-child{ border-bottom: 0; }
	.product .content img{ width: 70px; height: 70px;}
	.product .content .detail{display:flex;flex-direction:column;margin-left:7px;flex:1}
	.product .content .detail .t1{height: 30px;line-height: 15px;color: #000;}
	.product .content .detail .t2{height: 23px;line-height: 23px;color: #999;overflow: hidden;font-size:13px;}
	.product .content .detail .t3{display:flex;height:15px;line-height:15px;color: #ff4246;}
	.product .content .detail .x1{ flex:1}
	.product .content .detail .x2{ width:50px;font-size:16px;text-align:right;margin-right:4px}
	.product .content .comment{position:absolute;top:32px;right:5px;border: 1px #ffc702 solid; border-radius:5px;background:#fff; color: #ffc702;  padding: 0 5px; height: 23px; line-height: 23px;}

	.orderinfo{ width:100%;margin-top:5px;padding: 5px;background: #FFF;}
	.orderinfo .item{display:flex;width:100%;padding:5px 0;border-bottom:1px dashed #ededed;}
	.orderinfo .item:last-child{ border-bottom: 0;}
	.orderinfo .item .t1{width:100px;}
	.orderinfo .item .t2{flex:1;text-align:right}
	.orderinfo .item .red{color:red}

	.logistics{ width: 94%;  background: #fff; padding: 0 10px;display:flex;flex-direction:column;color: #979797;}
	.logistics .on{color: #23aa5e;}
	.logistics .item{display:flex;width: 96%;  margin: 0 2%;/*border-left: 1px #dadada solid;*/padding:0 0}
	.logistics .item .f1{ width:30px;position:relative}
	/*.logistics img{width: 15px; height: 15px; position: absolute; left: -8px; top:11px;}*/
	.logistics .item .f1 img{ width: 15px; height: 100%;}

	.logistics .item .f2{display:flex;flex-direction:column;flex:auto;padding:5px 0}
	.logistics .item .f2 .t1{font-size: 15px;}
	.logistics .item .f2 .t1{font-size: 13px;}
	</style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card layui-col-md12">
          <div class="layui-card-header">
						<div class="layui-tab layui-tab-brief">
							<ul class="layui-tab-title">
								<li {if input('param.type')==''}class="layui-this"{/if} onclick="location.href='{:url('tongji')}'">按商品统计</li>
								<li {if input('param.type')=='2'}class="layui-this"{/if} onclick="location.href='{:url('tongji')}/type/2'">按规格统计</li>
								{if getcustom('shoptongji3')}
								<li {if input('param.type')=='3'}class="layui-this"{/if} onclick="location.href='{:url('tongji')}/type/3'">销售统计</li>
								<li {if input('param.type')=='4'}class="layui-this"{/if} onclick="location.href='{:url('tongji')}/type/4'">销售指标</li>
								<li {if input('param.type')=='5'}class="layui-this"{/if} onclick="location.href='{:url('tongji')}/type/5'">销售转化率</li>
								{/if}
								{if getcustom('shopcatetj')}
								<li {if input('param.type')=='6'}class="layui-this"{/if} onclick="location.href='{:url('tongji')}/type/6'">按商品分类统计</li>
								{/if}
								{if getcustom('school_product')}
									{if $need_school==1}
									<li {if input('param.type')=='7'}class="layui-this"{/if} onclick="location.href='{:url('tongji')}/type/7'">按学校班级统计</li>
									{/if}
								{/if}
							</ul>
						</div>   
          </div>
          <div class="layui-card-body" pad15>
						<div class="layui-col-md12">
							<div style="float:left;padding-bottom:10px">
								<button class="layui-btn layui-btn-primary layuiadmin-btn-list" data-form-export="{:url('tjexcel')}/type/{$Request.param.type}">导出</button>
							</div>
							<div class="layui-form layui-form-search" style="float: right;">
								{if getcustom('school_product') && $need_school && $type==7}
								<div class="layui-inline">
									<div class="layui-input-inline">
										<select name="school_id" lay-filter="school_id">
											<option value="">请选择学校</option>
											{volist name="schoollist" id="school"}
											<option value="{$school.id}">{$school.name}</option>
											{/volist}
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<div class="layui-input-inline">
										<select name="grade_id" id="grade_id">
											<option value="">请选择班级</option>
										</select>
									</div>
								</div>
								{/if}

								{if getcustom('shoporder_tongji_category')}
									<div class="layui-inline">
										<label class="layui-form-label">{if $bid > 0}平台{/if}分类</label>
										<div class="layui-input-inline">
											<select name="cid">
												<option value="">全部</option>
												{foreach $clist as $cv}
													<option value="{$cv['id']}" {if $cv['id']==input('param.cid')}selected{/if}>{$cv['name']}</option>
													{foreach $cv['child'] as $v}
													<option value="{$v['id']}" {if $v['id']==input('param.cid')}selected{/if}>&nbsp;&nbsp;&nbsp;{$v['name']}</option>
														{foreach $v['child'] as $v3}
														<option value="{$v3['id']}" {if $v3['id']==input('param.cid')}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$v3['name']}</option>
														{/foreach}
													{/foreach}
												{/foreach}
											</select>
										</div>
									</div>
									{if $bid > 0}
										<div class="layui-inline">
											<label class="layui-form-label">商家分类</label>
											<div class="layui-input-inline">
												<select name="cid2">
													<option value="">全部</option>
													{foreach $clist2 as $cv}
														<option value="{$cv['id']}" {if $cv['id']==input('param.cid')}selected{/if}>{$cv['name']}</option>
														{foreach $cv['child'] as $v}
														<option value="{$v['id']}" {if $v['id']==input('param.cid')}selected{/if}>&nbsp;&nbsp;&nbsp;{$v['name']}</option>
														{/foreach}
													{/foreach}
												</select>
											</div>
										</div>
									{/if}
								{/if}

								<div class="layui-inline">
									<label class="layui-form-label">{:t('门店')}</label>
									<div class="layui-input-inline">
										<select name="mdid">
											<option value="">全部</option>
											{volist name="mendians" id="mendian"}
											<option value="{$mendian.id}">{$mendian.name}</option>
											{/volist}
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">配送方式</label>
									<div class="layui-input-inline">
										<select name="freight_id" lay-filter="freight_id">
											<option value="">全部</option>
											{volist name="freights" id="freight"}
											<option value="{$freight.id}">{$freight.name}</option>
											{/volist}
										</select>
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">{:t('会员')}ID</label>
									<div class="layui-input-inline">
										<input type="text" name="mid" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">下单时间</label>
									<div class="layui-input-inline" style="width: 175px">
										<input type="text" name="ctime" id="ctime" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<label class="layui-form-label">付款时间</label>
									<div class="layui-input-inline" style="width: 175px">
										<input type="text" name="paytime" id="paytime" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-inline">
									<button class="layui-btn layuiadmin-btn-replys" lay-submit="" lay-filter="LAY-app-forumreply-search">
										<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
									</button>
								</div>
							</div>
						</div>
						<div class="layui-col-md12">
							<table class="layui-table" lay-skin="line" lay-size="lg">
								<!-- <colgroup>
									<col width="150">
									<col width="200">
									<col width="200">
									<col>
								</colgroup> -->
								<thead>
									<tr>
										<th>总销售数量：<span id="total_num" style="font-weight:bold"></span></th>
										<th>总销售金额：<span id="total_totalprice" style="font-weight:bold"></span></th>
										{if $order_cost_hide==0}
										<th>总商品成本：<span id="total_chengben" style="font-weight:bold"></span></th>
										<th>毛利润：<span id="total_lirun" style="font-weight:bold"></span></th>
										{/if}
									</tr> 
								</thead>
								<!-- <tbody>
									<tr>
										<td id="total_num"></td>
										<td id="total_totalprice"></td>
										<td id="total_chengben"></td>
										<td id="total_lirun"></td>
									</tr>
								</tbody> -->
							</table>
						</div>

						<div class="layui-col-md12">
							<table id="tabledata" lay-filter="tabledata"></table>
						</div>
          </div>
        </div>
    </div>
  </div>
	{include file="public/js"/}
	<script>
  var table = layui.table;
	var datawhere = {};
	{if input('?param.status') && input('param.status')!==''}
	datawhere['status'] = "{$Request.param.status}";
	{/if}
  //数据表
  var tableIns = table.render({
    elem: '#tabledata'
    ,url: "{$Request.url}" //数据接口
    ,page: true //开启分页
		,autoSort:false
		//,size:'sm'
    ,cols: [[ //表头
			//{type:"checkbox"},
      {field: 'ph', title: '排名',width:70},
      {field: 'goodsdata', title: '商品名称',width:370,templet:function(d){
				return '<div class="flex"><img src="'+d.pic+'" style="width:50px;height:50px"/><div style="width:300px;margin-left:10px">' + d.name + '</div></div>';
      }},
		  {if getcustom('school_product')}
			  {if input('param.type')==7}
				{field: 'school_info', title: '学校班级',},
		  		{field: 'ggname', title: '商品规格'},
			  {/if}
		  {/if}
			{if input('param.type')==2}
			{field: 'ggname', title: '商品规格',},
			{/if}
			{field: 'num',sort: true, title: '销售数量'},
			{field: 'totalprice',sort: true, title: '销售金额'},
      {field: 'avgprice',sort: true, title: '平均单价'},
	  {if $order_cost_hide==0}
		  {field: 'chengben',sort: true, title: '总商品成本'},
		  {field: 'lirun',sort: true, title: '毛利润'},
	  {/if}
    ]]
		,done:function(res, curr, count){
			if(curr == 1){
				$('#total_num').html(res.totaldata.num);
				$('#total_totalprice').html(res.totaldata.totalprice);
				$('#total_chengben').html(res.totaldata.chengben);
				$('#total_lirun').html(res.totaldata.lirun);
			}
		}
  });
	//排序
	table.on('sort(tabledata)', function(obj){
		datawhere.field = obj.field;
		datawhere.order = obj.type;
		tableIns.reload({
			initSort: obj,
			where: datawhere
		});
	});
	//日期范围选择
	layui.laydate.render({ 
		elem: '#ctime',
		type:'datetime',
		trigger: 'click',
		range: '~' //或 range: '~' 来自定义分割字符
	});
	//日期范围选择
	layui.laydate.render({ 
		elem: '#paytime',
		trigger: 'click',
		range: '~' //或 range: '~' 来自定义分割字符
	});
	//检索
	layui.form.on('submit(LAY-app-forumreply-search)', function(obj){
		var field = obj.field
		var olddatawhere = datawhere
		datawhere = field
		datawhere.field = olddatawhere.field
		datawhere.order = olddatawhere.order
		tableIns.reload({
			where: datawhere,
			page: {curr: 1}
		});
	})
		{if getcustom('school_product')}
		layui.form.on('select(school_id)',function(data){
			var school_id = data.value;
			//请求数据
			$.ajax({
				type: 'post',
				dataType: 'json',
				url: "{:url('SchoolClass/getGradeBySchoolId')}",
				data: {
					school_id: school_id
				},
				success: function(res) {
					var gradelist = res.data
					var optionHtml = '<option value="">请选择班级</option>';
					for (let i in gradelist){
						optionHtml +='<option value="'+gradelist[i].id+'">'+gradelist[i].name+'</option>'
						for (let j in gradelist[i].child){
							var child = gradelist[i].child[j]
							optionHtml +='<option value="'+gradelist[i].id+'_'+child.id+'">&nbsp;&nbsp;&nbsp;'+child.name+'</option>'
						}
					}
					$('#grade_id').html(optionHtml);
					layui.form.render('select');
				},
				error: function() {
					layer.msg('查询班级信息失败！请刷新页面。');
				}
			});
		})
		{/if}
	</script>
	{include file="public/copyright"/}
</body>
</html>